import java.util.Stack;

class Solution {
    public boolean isPopOrder(int[] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        //目的用于遍历popA数组，判断栈顶元素是否与pop数组对应
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while( !stack.isEmpty() && j < popA.length && stack.peek() == popA[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }
}


public class Main {
    public static void main(String[] args) {
    }
}